//
//  HWAssetsCenterCell.swift
//  HWPromoteProjectAPP
//
//  Created by 王昌健 on 2022/1/27.
//  Copyright © 2022 王昌健. All rights reserved.
//

import UIKit

class HWAssetsCenterCell: UITableViewCell {
    var bgView:UIView!
    /// logo
    var leftImageView:UIImageView!
    /// 标题
    var titleLabel:UILabel!
    var rightLabel:UILabel!
    var rightArrowImageView:UIImageView!
    var rightPlaceHoderLabel:UILabel!
    var indexPath:IndexPath? {
        didSet {
            if indexPath?.row == 0 {
                rightLabel.isHidden = false
                let attriString = NSMutableAttributedString.init(string: "￥\(assetsModel?.money ?? "")")
                attriString.addAttribute(NSAttributedString.Key.font, value: UIFont.boldSystemFont(ofSize: 12*widthScale), range: NSMakeRange(0, 1))
                rightLabel.attributedText = attriString
                bgView.addCorner(conrners: [.topLeft,.topRight], radius: 12*widthScale)
            }else if indexPath?.row == 2 {
                bgView.addCorner(conrners: [.bottomLeft,.bottomRight], radius: 12*widthScale)
            }else {
                bgView.addCorner(conrners: [.topLeft,.topRight,.bottomLeft,.bottomRight], radius: 0)
            }
            if indexPath?.row == 1 {
                rightPlaceHoderLabel.isHidden = true
                rightArrowImageView.isHidden = true
                rightLabel.isHidden = false
                rightLabel.text = assetsModel?.popularizeNumber
            }
//            if indexPath?.row == 2 {
//                rightPlaceHoderLabel.isHidden = true
//                rightArrowImageView.isHidden = false
//                rightLabel.isHidden = true
//            } else
            if indexPath?.row == 2 {
                rightArrowImageView.isHidden = false
                rightPlaceHoderLabel.isHidden = false
                rightLabel.isHidden = true
            }else {
                rightArrowImageView.isHidden = true
                rightPlaceHoderLabel.isHidden = true
            }
        }
    }
    
    var assetsModel:HWAssetsModel? {
        didSet {
        }
    }
    
    class func cellWithTableView(tableView:UITableView) -> (HWAssetsCenterCell) {
        let reUse:String = "HWAssetsCenterCell"
        
        var cell = tableView.dequeueReusableCell(withIdentifier: reUse)
        
        if cell == nil {
            cell = HWAssetsCenterCell.init(style: UITableViewCell.CellStyle.default, reuseIdentifier: reUse)
        }
        
        return cell as! HWAssetsCenterCell
    }
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        initUI()
        initFrame()
    }
    
    func initUI() -> Void {
        selectionStyle = UITableViewCell.SelectionStyle.none
        backgroundColor = UIColor.clear
        
        bgView = UIView()
        
        bgView.frame = CGRect(x: 0, y: 0, width: 335*widthScale, height: 44*widthScale)
        bgView.backgroundColor = .white
        bgView.layer.masksToBounds = true
        contentView.addSubview(bgView)
        
        
        leftImageView = UIImageView()
        bgView.addSubview(leftImageView)
        
        titleLabel = HWLabel.createLabel(title: "", color: "#444444", font: 14*widthScale)
        bgView.addSubview(titleLabel)
        
        rightLabel = HWLabel.createBoldLabel(title: "", color: "#444444", font: 16*widthScale)
        bgView.addSubview(rightLabel)
        
        rightArrowImageView = UIImageView()
        rightArrowImageView.image = UIImage(named: "grayArrow")
        bgView.addSubview(rightArrowImageView)
        
        rightPlaceHoderLabel = HWLabel.createLabel(title: "快去推广拿佣金！", color: "#C1C1CB", font: 12*widthScale)
        bgView.addSubview(rightPlaceHoderLabel)
        
        rightArrowImageView.isHidden = true
        rightPlaceHoderLabel.isHidden = true
        
    }
    
    func initFrame() -> Void {
        bgView.snp.makeConstraints { make in
            make.top.equalTo(0)
            make.left.equalTo(20*widthScale)
            make.right.equalTo(-20*widthScale)
            make.height.equalTo(44*widthScale)
            make.bottom.equalTo(-1)
        }
        
        leftImageView.snp.makeConstraints { make in
            make.left.equalTo(20*widthScale)
            make.width.height.equalTo(20*widthScale)
            make.centerY.equalToSuperview()
        }

        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(leftImageView.snp.right).offset(6*widthScale)
            make.centerY.equalToSuperview()
        }

        rightLabel.snp.makeConstraints { make in
            make.right.equalTo(-20*widthScale)
            make.centerY.equalToSuperview()
        }
        
        rightArrowImageView.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.right.equalTo(-20*widthScale)
            make.width.height.equalTo(12*widthScale)
        }
        
        rightPlaceHoderLabel.snp.makeConstraints { make in
            make.right.equalTo(rightArrowImageView.snp.left)
            make.centerY.equalToSuperview()
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
